(in-package :User)


;;;=========================================================================
;;; A mini package for showing the results of test cases.
;;; Eg:
;;; (Show-Output
;;;   (+ 2 3)
;;;   (list 'A 'B 'C)
;;;   (cons 'A (list (* 6 7))))
;;;
;;; > (+ 2 3)
;;; 5
;;;
;;; > (LIST 'A 'B 'C)
;;; (A B C)
;;;
;;; > (CONS 'A (LIST (* 6 7)))
;;; (A 42)
;;;
;;; 2/95 Marty Hall. marty_hall@jhuapl.edu
;;;=========================================================================
;;;=========================================================================

;;;=========================================================================

(defmacro Show-Output (&body Forms)
  "Takes a number of list forms, and prints out each form and its resultant
   value. Prints a '>' in front of the form, since '>' is a common prompt"
  `(progn ,@(apply #'append (mapcar #'Print-and-Eval Forms))
     (values)))

;;;=========================================================================
;;; Same as Show-Output, but the first argument must be a stream to which
;;; to direct the printout.

(defmacro Show-Output-on-Stream (Stream &body Forms)
  "Same as Show-Output, but the first arg must be a stream to which to direct
   the printout."
  `(progn ,@(apply #'append (mapcar #'(lambda (Form)
					(Print-and-Eval Form Stream))
				    Forms))
     (values)))

;;;=========================================================================

(defun Print-and-Eval (Form &optional (Stream t))
  `((let ((*print-pretty* t))
      (format ,Stream "> ~S" ',Form))
    (pprint (eval ',Form) ,Stream)
    (terpri ,Stream)
    (terpri ,Stream)))

;;;=========================================================================